package com.neteast.androidclient.contact.activity;

import com.neteast.androidclient.contact.R;
import com.neteast.androidclient.contact.Test;
import com.neteast.androidclient.contact.domain.ContactRowManager;
import com.neteast.androidclient.contact.widget.InfoDetailPanel;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class NewContactActivity extends Activity{
	private Context mContext;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		final InfoDetailPanel infoDetail=new InfoDetailPanel(NewContactActivity.this, Test.getContact());
		setContentView(infoDetail);
		init();
		final ToggleButton editInfo = (ToggleButton) infoDetail.findViewById(R.id.btn_edit_info);
		editInfo.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				editInfo.setChecked(isChecked);
				if (isChecked) {
					infoDetail.openEditState();
				}else {
					infoDetail.closeEditState();
					ContactRowManager.clearRowsCache();
				}
			}
		});
	}
	private void init() {
		WindowManager wManager = getWindowManager();
		Display display = wManager.getDefaultDisplay();
		LayoutParams lParams = getWindow().getAttributes();
		lParams.height = display.getHeight();
		lParams.width = 415;
		getWindow().setAttributes(lParams);
		getWindow().setGravity(Gravity.RIGHT);
		mContext = NewContactActivity.this;
	}
	@Override
	protected void onDestroy() {
		super.onDestroy();
		ContactRowManager.clearRowsCache();
	}

}
